home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3742 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.4 KB

  1. Path: news.ios.com!usenet
  2. From: John Leonard <leonardj@tribeca.ios.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Constructors and exceptions
  5. Date: Thu, 25 Jan 1996 10:58:17 -0500
  6. Organization: 12th of Nov, Inc
  7. Message-ID: <3107A899.4A86@tribeca.ios.com>
  8. NNTP-Posting-Host: ppp-27.ts-9.hck.idt.net
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b4 (Win95; I)
  13.  
  14. Let's say that you have a class, we'll call it WindowClass, which, when it is constructed, 
  15. opens a file, allocates memory for the file, reads the file into memory, and then opens a window. 
  16. Let's say furthermore that you are going to create the object with a call to 'new' like this:
  17.  
  18.      WindowClass     *aWC = new WindowClass(filename);
  19.  
  20.      Now let's say that during initialization of the object, after it allocates the memory it finds 
  21. that it cannot open the window. At this point I suppose it would be necessary to de-allocate the 
  22. memory that had been allocated and close the file, then throw an exception. Now as far as I can tell 
  23. when you use 'new' like this to allocate and initialize an object two things must happen: 
  24. first, space must be reserved by the 'new' function for the objects data members, then, the 
  25. constructor is called. If this process aborts after the memory has been allocated how can the 
  26. application free it?
  27.      Thanks,
  28.      John Leonard
  29.